var languageCommon= {
	"zeroRecords" : "对不起，查询不到任何相关数据",
	"info" : "  _START_ 到 _END_ 条,共_TOTAL_条",
	"infoEmpty" : "记录数为0",
	"infoFiltered": "(从 _MAX_ 条记录过滤)",
	"loadingRecords": "请稍等，正在加载...",
	"lengthMenu": "每页显示 _MENU_ 条记录",
	"processing": "正在加载...",
	"search" : "搜索",
	"paginate": {
         "first": "<<",
         "last": ">>",
         "next": ">",
         "previous": "<"
    }
};
var changePageLength=[[10,20,30,40,50,-1], [10,20,30,40,50,"All"]];
var buttonsCommon=[{ extend: 'collection',
    text: '导出&nbsp;&nbsp;<i class="fa fa-download" style="font-size: 12px;color: #15bb6b;"></i>',
    buttons: [{ extend: 'csv',charset:'utf-8',bom:true },{ extend: 'excel',charset:'utf-8',bom:true },'copy']
    }
    
];
var pageing = true;//是否分页
var exportEnable=true;//是否可导出
var domCommon='<"top"Bfl>rt<"bottom"ip><"clear">';
$(function(){
	//获取导出权限配置
	$.post(contextPath + "/systemConfig/getConfigByCode.dhc",{ 'alterParam': 'DATA_EXPORT_ROLE'}).done(function(result){
		var configValue = result.data;
		var dataExpRoleName = configValue;	
		/**
		   * 根据导出权限配置，删除导出button
		   */
		if(dataExpRoleName=="" || dataExpRoleName==undefined){
			dataExpRoleName = ",";
		}
		var dataExpArr = dataExpRoleName.split(",");
		var roleNameNow= $("#roles").html();//直接获取当前用户的角色
		if($.inArray(roleNameNow, dataExpArr) < 0){
			exportEnable=false;
			buttonsCommon=[];//如果没有导出权限，则将定义的公共button清空
		}
	});
	//获取是否分页配置
	$.post(contextPath + "/systemConfig/getConfigByCode.dhc",{ 'alterParam': 'PAGEING'}).done(function(result){
		pageing= result.data=="0"?false:true;
	});
})
/**
 * _columns 自定义列
 *_data 数据源
 * paramsDataTables dataTables参数
 */
jQuery.fn.dataTableBasic=function(_columns, _data,paramsDataTables){
	addDataTableHeadClass();//添加表头对齐class
	var datatable = $(this);
	var columnDefsCommon= [{'defaultContent': '','targets': '_all'}];
	if(paramsDataTables==undefined){
		paramsDataTables={};
	}
	var searching = paramsDataTables.searching==false?false:true;//是否启用过滤，默认true
	var paging=paramsDataTables.paging==false?false:true;//是否启用分页,默认设置为true,最终是否分页由此参数与系统配置中的设置一起决定
	var ordering = paramsDataTables.ordering==false?false:true;//是否启用排序
	var lengthChange=paramsDataTables.lengthChange==false?false:true;//是否允许调整每页的条数
	var lengthMenu=paramsDataTables.lengthMenu==undefined?changePageLength:paramsDataTables.lengthMenu;//
	var pageLength=paramsDataTables.pageLength==undefined?10:paramsDataTables.pageLength;//默认的分页条数
	var info=paramsDataTables.info==false?false:true;//是否显示页脚信息
	var scrollX=paramsDataTables.scrollX==true?true:false;//是否启用水平滚动 默认为false
	var scrollY=paramsDataTables.scrollY==undefined?false:paramsDataTables.scrollY;//设置纵向滚动（如：250px）
	var autoWidth=paramsDataTables.autoWidth==false?false:true;//是否自动计算列宽，默认为true
	var order=paramsDataTables.order==undefined?false:paramsDataTables.order;//设置排序的数组，如果不设置就传入false,初始化排序
	var dom=paramsDataTables.dom==undefined?domCommon:paramsDataTables.dom;//自定义dom元素
	var fixedColumns=paramsDataTables.fixedColumns==undefined?{}:paramsDataTables.fixedColumns;//锁定列
	if(paramsDataTables.columnDefs!=undefined){//定义columnDefs
		if(paramsDataTables.columnDefs instanceof Array){//判断是否为数组
			for(var o in paramsDataTables.columnDefs){
				columnDefsCommon.push(paramsDataTables.columnDefs[o]);
			}
		}
	}
	var buttonsCustom = jQuery.extend(true, [],buttonsCommon);//此处复制时，用[],不用{}
    if(paramsDataTables.buttons!=undefined){//定义columnDefs
    	for(var o in paramsDataTables.buttons){
    		buttonsCustom.push(paramsDataTables.buttons[o]);
		}
	}
	var jQueryUI=paramsDataTables.jQueryUI==true?true:false;//是否启用jQueryUI 默认为false
	var stateSave=paramsDataTables.stateSave==true?true:false;//是否保存table状态，默认为false 当开启了状态储存，Datatables会存储一个状态到浏览器上， 包含分页位置，每页显示的长度，过滤后的结果和排序，重新刷新页面，表格的状态将会被设置为之前的设置
	var retrieve=paramsDataTables.retrieve==true?true:false;//默认为false 检索已存在的Datatables实例，即如果已经初始化了，则继续使用之前的Datatables实例
	var orderCellsTop=paramsDataTables.orderCellsTop==true?true:false;//默认为false 控制表头(colspan rowspan 表头)的哪一个单元格可以应用于该列的排序响应
	var rownumbers=paramsDataTables.rownumbers==true?true:false;//默认为false
	
	//如果有导出权限，设置标题
	if(exportEnable){
		buttonsCustom[0].buttons[0].filename='*';
		buttonsCustom[0].buttons[1].filename='*';
		
		if(datatable.parents().hasClass('dataChangeSel')){
			var $currdt = datatable.parents(".dataChangeSel");
			var titleText=$currdt.find(".contaotalsccq").text();
			if(titleText!=''){
				buttonsCustom[0].buttons[0].filename=titleText;
				buttonsCustom[0].buttons[1].filename=titleText;
			}
		}
		else if(paramsDataTables.tableTitle!=undefined&&paramsDataTables.tableTitle!=""){
			buttonsCustom[0].buttons[0].filename=paramsDataTables.tableTitle;
			buttonsCustom[0].buttons[1].filename=paramsDataTables.tableTitle;
		}
	}

	var option = {
		 "destroy": true,//允许重新实例化Datatables
		 "paging":pageing&&paging,//是否分页
		 "searching":searching,//过滤功能
		 "ordering":ordering,//是否启用字段排序
    	 "lengthChange": lengthChange,//是否改变每页显示条数
    	 "pageLength":pageLength,
    	 "info":info,//页脚信息
	     "scrollX":scrollX,
	     "scrollY":scrollY,
	     "buttons": buttonsCustom,
	     "autoWidth":autoWidth,//是否自动计算单元格宽度
    	 "stateSave": false,
    	 "columnDefs":columnDefsCommon,
    	 "jQueryUI":jQueryUI,
    	 "stateSave":stateSave,
    	 "retrieve":retrieve,
    	 "orderCellsTop":orderCellsTop,
    	 "rownumbers":rownumbers,
    	 "dom": dom,//l - Length changing 改变每页显示多少条数据的控件,f - Filtering input 即时搜索框控件,t - The Table 表格本身,i - Information 表格相关信息控件, p - Pagination 分页控件 ,r - pRocessing 加载等待显示信息
         "data":_data,//数据源
    	 "pagingType": "full_numbers",
    	 "lengthMenu": lengthMenu,
    	 "columns":_columns,
    	 "initComplete": function(settings, json) {
		 	exportTableLog() ;
 	    	removeDataTableHeadClass();//移除表头对齐class
     	   },//绘制完后
 	    "language":languageCommon,
 		"fixedColumns" :fixedColumns 
 	   }
	if(paramsDataTables.dom!=undefined){
		option.dom=paramsDataTables.dom;
	}
	if(order){
		option.order=order;
	}
	if(paramsDataTables.drawCallback!=undefined){
		option.drawCallback=paramsDataTables.drawCallback;
	}
	if(paramsDataTables.initComplete!=undefined){
		var initComplete=paramsDataTables.initComplete;
		var initCompleteOption=option.initComplete;
		var initCompleteFinal=function(){
            initCompleteOption() ;
			initComplete();
			removeDataTableHeadClass();//移除表头对齐class
		};
		option.initComplete=initCompleteFinal;
	}
	if(paramsDataTables.createdRow!=undefined){
		option.createdRow=paramsDataTables.createdRow;
	}
	if(paramsDataTables.fixedColumns!=undefined){
		option.fixedColumns=paramsDataTables.fixedColumns;
		option.scrollCollapse=true;
	}
	else{
		option.fixedColumns=false;
	}
	var table;
	try {
		table = $(this).DataTable(option);
	} catch (e) {
		console.error(e);
		removeDataTableHeadClass();//移除表头对齐class
	}
    return table;
};
/**服务器段分页
 * _columns 自定义列
 * paramsDataTables dataTables参数
 */
jQuery.fn.dataTableServerPaging=function(_columns,paramsDataTables){
//	addDataTableHeadClass();//添加表头对齐class
	var datatable = $(this);
	var columnDefsCommon= [{'defaultContent': '','targets': '_all'}]
	var searching = paramsDataTables.searching==false?false:true;//是否启用过滤，默认true
	var ordering = paramsDataTables.ordering==false?false:true;//是否启用排序
	var lengthChange=paramsDataTables.lengthChange==false?false:true;//是否允许调整每页的条数
	var lengthMenu=paramsDataTables.lengthMenu==undefined?changePageLength:paramsDataTables.lengthMenu;
	var pageLength=paramsDataTables.pageLength==undefined?10:paramsDataTables.pageLength;//默认的分页条数
	var info=paramsDataTables.info==false?false:true;//是否显示页脚信息
	var scrollX=paramsDataTables.scrollX==true?true:false;//是否启用水平滚动 默认为false
	var scrollY=paramsDataTables.scrollY==undefined?false:paramsDataTables.scrollY;//是否设置垂直滚动
	var autoWidth=paramsDataTables.autoWidth==false?false:true;//是否自动计算列宽，默认为true
	var order=paramsDataTables.order==undefined?false:paramsDataTables.order;//如果不设置就传入false,初始化排序
	if(paramsDataTables.columnDefs!=undefined){//定义columnDefs
		if(paramsDataTables.columnDefs instanceof Array){//判断是否为数组
			for(var o in paramsDataTables.columnDefs){
				columnDefsCommon.push(paramsDataTables.columnDefs[o]);
			}
		}
	}
	var jQueryUI=paramsDataTables.jQueryUI==true?true:false;//是否启用jQueryUI 默认为false
	var stateSave=paramsDataTables.stateSave==true?true:false;//是否保存table状态，默认为false 当开启了状态储存，Datatables会存储一个状态到浏览器上， 包含分页位置，每页显示的长度，过滤后的结果和排序，重新刷新页面，表格的状态将会被设置为之前的设置
	var retrieve=paramsDataTables.retrieve==true?true:false;//默认为false 检索已存在的Datatables实例，即如果已经初始化了，则继续使用之前的Datatables实例
	var orderCellsTop=paramsDataTables.orderCellsTop==true?true:false;//默认为false 控制表头(colspan rowspan 表头)的哪一个单元格可以应用于该列的排序响应
	var rownumbers=paramsDataTables.rownumbers==true?true:false;//默认为false
	var ajaxFunction=paramsDataTables.ajaxFunction==undefined?"":paramsDataTables.ajaxFunction;//异步加载数据的函数
	var dom=paramsDataTables.dom==undefined?domCommon:paramsDataTables.dom;//自定义dom元素
	
	var buttonsCustom = jQuery.extend(true, [],buttonsCommon);//此处复制时，用[],不用{}
	if(exportEnable){
		buttonsCustom[0].buttons[0].filename='*';
		buttonsCustom[0].buttons[1].filename='*';
		
		if(datatable.parents().hasClass('dataChangeSel')){
			var $currdt = datatable.parents(".dataChangeSel");
			var titleText=$currdt.find(".contaotalsccq").text();
			if(titleText!=''){
				buttonsCustom[0].buttons[0].filename=titleText;
				buttonsCustom[0].buttons[1].filename=titleText;
			}
		}
		else if(paramsDataTables.tableTitle!=undefined&&paramsDataTables.tableTitle!=""){
			buttonsCustom[0].buttons[0].filename=paramsDataTables.tableTitle;
			buttonsCustom[0].buttons[1].filename=paramsDataTables.tableTitle;
		}
	}
	var option = {
			 "processing" : true,
			 "serverSide" : true,
			 "destroy": true,//允许重新实例化Datatables
			 "paging":true,//是否分页
			 "searching":searching,//过滤功能
			 "ordering":ordering,//是否启用字段排序
	    	 "lengthChange": lengthChange,//是否改变每页显示条数
	    	 "pageLength":pageLength,
	    	 "info":info,//页脚信息
		     "scrollX":scrollX,
		     "scrollY":scrollY,
		     "buttons": buttonsCustom,
		     "autoWidth":autoWidth,//是否自动计算单元格宽度
	    	 "stateSave": false,
	    	 "columnDefs":columnDefsCommon,
	    	 "jQueryUI":jQueryUI,
	    	 "stateSave":stateSave,
	    	 "retrieve":retrieve,
	    	 "orderCellsTop":orderCellsTop,
	    	 "rownumbers":rownumbers,
	    	 "dom": dom,//l - Length changing 改变每页显示多少条数据的控件,f - Filtering input 即时搜索框控件,t - The Table 表格本身,i - Information 表格相关信息控件, p - Pagination 分页控件 ,r - pRocessing 加载等待显示信息
	         "pagingType": "full_numbers",
	    	 "lengthMenu": lengthMenu,
	    	 "columns":_columns,
	 	     "language":languageCommon,
	 	     "initComplete": function(settings, json) {
//		    	removeDataTableHeadClass();//移除表头对齐class
	    	   },//绘制完后
	 	     "ajax":ajaxFunction
	 	   }
		if(order!=false){
			option.order=order;
		}
		if(paramsDataTables.drawCallback!=undefined){
			option.drawCallback=paramsDataTables.drawCallback;
		}
		if(paramsDataTables.rowCallback!=undefined){
			option.rowCallback=paramsDataTables.rowCallback;
		}
		if(paramsDataTables.initComplete!=undefined){
			var initComplete=paramsDataTables.initComplete;
			var initCompleteFinal=function(){
				initComplete();
				removeDataTableHeadClass();//移除表头对齐class
			};
			option.initComplete=initCompleteFinal;
		}
		if(paramsDataTables.fixedColumns!=undefined){
			option.fixedColumns=paramsDataTables.fixedColumns;
			option.scrollCollapse=true;
		}
		else{
			option.fixedColumns=false;
		}
		var table;
		try {
			table = $(this).DataTable(option);
		} catch (e) {
			console.error(e);
			removeDataTableHeadClass();//移除表头对齐class
		}
		return table;
}	
/**
 * datatable函数扩展
 * columns 自定义列
 * data 数据源
 * paging 是否分页(0、1)
 * searching 是否启用过滤(0、1)
 * bSort 是否启用排序(0、1)
 * sortCols 排序列(0、1、2、3、4...)
 * aTargets 启用某列不排序
 */
jQuery.fn.drgsDataTable=function(columns, data, paramsDataTables){
	addDataTableHeadClass();//添加表头对齐class
	data=data!=undefined?data:[];//传入的数据源为空时，处理为[]
	var datatable = $(this);
	var columnDefsCommon= [{'defaultContent': '','targets': '_all'}];
	if(paramsDataTables==undefined){
		paramsDataTables={};
	}
	var searching = paramsDataTables.searching==false?false:true;//是否启用过滤，默认true
	var paging=paramsDataTables.paging==false?false:true;//是否启用分页,默认设置为true,最终是否分页由此参数与系统配置中的设置一起决定
	var ordering = paramsDataTables.ordering==false?false:true;//是否启用排序
	var lengthChange=paramsDataTables.lengthChange==false?false:true;//是否允许调整每页的条数
	var lengthMenu=paramsDataTables.lengthMenu==undefined?changePageLength:paramsDataTables.lengthMenu;//
	var pageLength=paramsDataTables.pageLength==undefined?10:paramsDataTables.pageLength;//默认的分页条数
	var info=paramsDataTables.info==false?false:true;//是否显示页脚信息
	var scrollX=paramsDataTables.scrollX==true?true:false;//是否启用水平滚动 默认为false
	var scrollY=data.length==0?false:'310px';//设置纵向滚动（如：250px）
	var autoWidth=paramsDataTables.autoWidth==false?false:true;//是否自动计算列宽，默认为true
	var order=paramsDataTables.order==undefined?false:paramsDataTables.order;//设置排序的数组，如果不设置就传入false,初始化排序
	var dom=paramsDataTables.dom==undefined?domCommon:paramsDataTables.dom;//自定义dom元素
	if(paramsDataTables.columnDefs!=undefined){//定义columnDefs
		if(paramsDataTables.columnDefs instanceof Array){//判断是否为数组
			for(var o in paramsDataTables.columnDefs){
				columnDefsCommon.push(paramsDataTables.columnDefs[o]);
			}
		}
	}
	
	var buttonsCustom = jQuery.extend(true, [],buttonsCommon);//此处复制时，用[],不用{}
    if(exportEnable) {
    	buttonsCustom[0].buttons[0].filename = '*';
    	buttonsCustom[0].buttons[1].filename = '*';
    	if(datatable.parents().hasClass('dataChangeSel')){
			var $currdt = datatable.parents(".dataChangeSel");
			var titleText=$currdt.find(".contaotalsccq").text();
			if(titleText!=''){
				buttonsCustom[0].buttons[0].filename=titleText;
				buttonsCustom[0].buttons[1].filename=titleText;
			}
		}
    }
	var option = {
		"dom":dom,
		"destroy": true,
		"paging": pageing&&paging, //翻页功能
		"lengthChange": lengthChange, //改变每页显示数据数量
		"searching": searching, //过滤功能
		"info": info, //页脚信息
	    "data": data,
	    "buttons":buttonsCustom,
	    "autoWidth":autoWidth,//是否自动计算单元格宽度
	    "stateSave": false, 
	    "ordering": ordering,
	    "pageLength": pageLength,
	    "lengthMenu": lengthMenu,
	    "scrollX": scrollX,
	    "scrollY": scrollY,
	    "columnDefs": columnDefsCommon,
	    "pagingType": "full_numbers",
	    "columns": columns,
	    "language":languageCommon,
	    "initComplete": function(settings, json) {		
	    	removeDataTableHeadClass();//移除表头对齐class
    	   },//绘制完后
	    "drawCallback": function( oSettings ) { 
	    	/*
	    	   * 加载图表，更新数据,修改表头样式
	    	   */
	          if(datatable.parents().hasClass('dataChangeSel')) {
	        	  /**
	        	   * 加载左边图表数据
	        	   */
	        	  getPageDataYiZheng(oSettings._iDisplayStart,oSettings._iDisplayLength,oSettings.aiDisplay,oSettings.aoData,datatable);
	        	 
		      }
	    
	        	// 初始化提示工具
	        	$("[data-toggle='tooltip']").tooltip(); 
	        } 
		}
		if(order){
			option.order=order;
		}
	
	
		//加载datatables
		var table;
		try {
			table = $(this).DataTable(option);
		} catch (e) {
			console.error(e);
			removeDataTableHeadClass();//移除表头对齐class
		}
	
	/**
	 * 
	 * ECharts图表数据实时更新
	 * 
	 */
		function getPageDataYiZheng(iDisplayStart,iDisplayLength,aiDisplay,aoData,npaging){
			var $this = npaging;
			var dataLen = aoData.length;
			var quotaCodeId = $this.parents('.dataChangeSel').parents('.tab-pane').attr("id");
			var monitorName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("monitorName");
			var quotaName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("quotaName");
			var quotaCode = $this.parents('.dataChangeSel').parents('.tab-pane').attr("quotaCode");
			var quotaType = $this.parents('.dataChangeSel').parents('.tab-pane').attr("quotaType");
			var compareName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("compareName");
			var compareType = paramTabPage[tabId].compareType;
			if(!compareName){
				compareName = "";
			}
			
			var eChartsData = [];
			if(iDisplayLength < 0){
				iDisplayLength = aoData.length;
			}
			for (var i=iDisplayLength-1; i>=0; i--){
				var aDatanum = aiDisplay[iDisplayStart+i];
				if(typeof(aoData[aDatanum]) != "undefined"){
					var aData = aoData[aDatanum]._aData;
					if(compareName == ""){
						if(aData.ccode==null || aData.ddesc==null){
							eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue});
						}else{
							if(monitorName=="MDC"||monitorName=="ADRG"||monitorName=="DRG"){
								if(aData.ccode=="notcode"){
									eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue});
								}else{
									eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue});
								}
							}else{
								eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue});
							}
						}
					}else{
						if(aData.ccode==null || aData.ddesc==null){
							eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue,"ccodecc":"未入组","QuotaValuecc":aData.QuotaValuecc,"ddesccc":"未入组"});
						}else{
							if(monitorName=="MDC"||monitorName=="ADRG"||monitorName=="DRG"){
								if(aData.ccode=="notcode"){
									eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue,"ccodecc":"未入组","QuotaValuecc":aData.QuotaValuecc,"ddesccc":"未入组"});
								}else{
									eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue,"ccodecc":aData.ccodecc,"QuotaValuecc":aData.QuotaValuecc,"ddesccc":aData.ddesccc});
								}
								
							}else{
								eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue,"ccodecc":aData.ccodecc,"QuotaValuecc":aData.QuotaValuecc,"ddesccc":aData.ddesccc});
							}
						}
					}
				}
			}
			$("#"+tabId+" #"+quotaCodeId+" div div .echartscq").empty();
			var bars = [{"code": "QuotaValue", "desc": "本期"+$(".time_id").html(), "data":[]}, {"code": "QuotaValuecc", "desc":compareName+getTime(compareType), "data":[]}];
			if(compareName == ""){
				bars = [{"code": "QuotaValue", "desc": "本期"+$(".time_id").html(), "data":[]}];
			}
			/*
			 * 获取datatables高度并赋值给echarts
			 */
			var echartsContainer = $("#"+tabId+" #"+quotaCodeId+" div div .echartscq");
			//当取不到值的时候
			if(echartsContainer.size()==0){
			   var table_div = datatable.parents(".dataChangeSel");
				echartsContainer=$(table_div).prev().find('.echartscq');
			}
			var datatabelContainer = $this.parents('.dataChangeSel');
			var datatablesHeight = datatabelContainer.height();
			if(dataLen == 0){
				echartsContainer.height(250);
			}else if(datatablesHeight > 0 && dataLen < 4){
				echartsContainer.height(datatablesHeight+50);//此处不要减少高度，是解决系统不分页时，echarts里只有两个数据时的重叠问题
			}else{
				if(!pageing){
					echartsContainer.height(datatablesHeight+50)
				}
				else{
					echartsContainer.height(datatablesHeight)
				}
			}
			var chartParams={isHorizontal:true,isStack:false,legendPosition:'bottom',barMaxWidth:20};
			if(monitorName=="MDC" || monitorName=="ADRG" || monitorName=="DRG"){
				chartParams.showCode=true;
				if(quotaType=="ratio"){
					barChart(echartsContainer, bars, eChartsData, quotaName+"统计(%)", monitorName,chartParams);
				}else{
					barChart(echartsContainer, bars, eChartsData, quotaName+"统计", monitorName,chartParams);
				}
				
			}else{
				if(quotaType=="ratio"){
					barChart(echartsContainer, bars, eChartsData, quotaName+"统计(%)", monitorName,chartParams);
				}else{
					barChart(echartsContainer, bars, eChartsData, quotaName+"统计", monitorName,chartParams);
				}
			}	
			$('#'+tabId+' a[href="#'+quotaCodeId+'"]').on('shown.bs.tab', function (e) {
				var chartParams={isHorizontal:true,isStack:false,legendPosition:'bottom',barMaxWidth:20};
				if(monitorName=="MDC" || monitorName=="ADRG" || monitorName=="DRG"){
					chartParams.showCode=true;
					if(quotaType=="ratio"){
						barChart(echartsContainer, bars, eChartsData, quotaName+"统计(%)",  monitorName,chartParams);
					}else{
						barChart(echartsContainer, bars, eChartsData, quotaName+"统计",  monitorName,chartParams);
					}
				}else{
					if(quotaType=="ratio"){
						barChart(echartsContainer, bars, eChartsData, quotaName+"统计(%)",  monitorName,chartParams);
					}else{
						barChart(echartsContainer, bars, eChartsData, quotaName+"统计",  monitorName,chartParams);
					}
				}
			});		
		}
};

/**
 * datatable函数扩展，医保角色
 * columns 自定义列
 * data 数据源
 * paging 是否分页(0、1)
 * searching 是否启用过滤(0、1)
 * bSort 是否启用排序(0、1)
 * sortCols 排序列(0、1、2、3、4...)
 * aTargets 启用某列不排序
 */
jQuery.fn.drgsDataTableyb=function(columns, data, paramsDataTables){
	var monitorType=paramsDataTables.monitorType==undefined?'':paramsDataTables.monitorType;
	addDataTableHeadClass();//添加表头对齐class
	data=data!=undefined?data:[];//传入的数据源为空时，处理为[]
	var datatable = $(this);
	var columnDefsCommon= [{'defaultContent': '','targets': '_all'}];
	if(paramsDataTables==undefined){
		paramsDataTables={};
	}
	var searching = paramsDataTables.searching==false?false:true;//是否启用过滤，默认true
	var paging=paramsDataTables.paging==false?false:true;//是否启用分页,默认设置为true,最终是否分页由此参数与系统配置中的设置一起决定
	var ordering = paramsDataTables.ordering==false?false:true;//是否启用排序
	var lengthChange=paramsDataTables.lengthChange==false?false:true;//是否允许调整每页的条数
	var lengthMenu=paramsDataTables.lengthMenu==undefined?changePageLength:paramsDataTables.lengthMenu;//
	var pageLength=paramsDataTables.pageLength==undefined?10:paramsDataTables.pageLength;//默认的分页条数
	var info=paramsDataTables.info==false?false:true;//是否显示页脚信息
	var scrollX=paramsDataTables.scrollX==true?true:false;//是否启用水平滚动 默认为false
	var scrollY=data.length==0?false:'310px';//设置纵向滚动（如：250px）
	var autoWidth=paramsDataTables.autoWidth==false?false:true;//是否自动计算列宽，默认为true
	var order=paramsDataTables.order==undefined?false:paramsDataTables.order;//设置排序的数组，如果不设置就传入false,初始化排序
	var dom=paramsDataTables.dom==undefined?domCommon:paramsDataTables.dom;//自定义dom元素
	if(paramsDataTables.columnDefs!=undefined){//定义columnDefs
		if(paramsDataTables.columnDefs instanceof Array){//判断是否为数组
			for(var o in paramsDataTables.columnDefs){
				columnDefsCommon.push(paramsDataTables.columnDefs[o]);
			}
		}
	}
	
	var buttonsCustom = jQuery.extend(true, [],buttonsCommon);//此处复制时，用[],不用{}
	if(exportEnable) {
    	buttonsCustom[0].buttons[0].filename = '*';
    	buttonsCustom[0].buttons[1].filename = '*';
    	if(datatable.parents().hasClass('dataChangeSel')){
			var $currdt = datatable.parents(".dataChangeSel");
			var titleText=$currdt.find(".contaotalsccq").text();
			if(titleText!=''){
				buttonsCustom[0].buttons[0].filename=titleText;
				buttonsCustom[0].buttons[1].filename=titleText;
			}
		}
    }
	var option = {
		"dom":dom,
		"destroy": true,
		"paging": pageing&&paging, //翻页功能
		"lengthChange": lengthChange, //改变每页显示数据数量
		"searching": searching, //过滤功能
		"info": info, //页脚信息
	    "data": data,
	    "buttons":buttonsCustom,
	    "autoWidth":autoWidth,//是否自动计算单元格宽度
	    "stateSave": false, 
	    "ordering": ordering,
	    "pageLength": pageLength,
	    "lengthMenu": lengthMenu,
	    "scrollX": scrollX,
	    "scrollY": scrollY,
	    "columnDefs": columnDefsCommon,
	    "pagingType": "full_numbers",
	    "columns": columns,
	    "language":languageCommon,
	    "initComplete": function(settings, json) {		
	    	removeDataTableHeadClass();//移除表头对齐class
	    },//绘制完后
	    "drawCallback": function( oSettings ) { //table加载完成后回调事件
	          if(datatable.parents().hasClass('dataChangeSel')){
	        	  /**
	        	   * 加载左边图表数据
	        	   */
	        	  getPageDataYiBao(oSettings._iDisplayStart,oSettings._iDisplayLength,oSettings.aiDisplay,oSettings.aoData,datatable);
		      }
	        } 
		};
	if(order){
		option.order=order;
	}
	var oaTable;
	try {
		oaTable=$(this).DataTable(option);
		 //添加表格展开详情事件
		$(this).find("tbody").off("click", "td.details-control");
		$(this).find("tbody").on('click', 'td.details-control', function () {
			var nTr = $(this).closest('tr');
			var row = oaTable.row( nTr );
			if (row.child.isShown()){//判断是否已打开
				row.child.hide();
				nTr.removeClass("shown");
			} else {
				nTr.addClass("shown");
				//获取要查询的关联指标的指标代码
				var condation=[];
				var quota_rel = datatable.parents(".paddingd10").find("ul>li.active a").attr("href");
				var quotaName = datatable.parents(".paddingd10").find("ul>li.active a").html();
				quota_rel = quota_rel.substr(1,quota_rel.lastIndexOf("-")-1);
				//请求当前指标的关联指标
				$.ajax({
				    url: contextPath+"/DrgsIndexCal/releateQuotas.dhc?quotaCode="+quota_rel+"_RELEATE",
				    type: "POST",
				    dataType: 'JSON',
				    async: false,
				    success: function(result){
				    	if(result.success && result.data){
					    	var relQuota = result.data;
					    	condation.push(quota_rel);
				            condation.push(quotaName);
				            condation.push(relQuota);
				    	}
				    }
				});	            
				// 调用方法显示详细信息 data_id为自定义属性 存放配置ID，monitorType为类型，condation条件数组
				fnFormatDetails(nTr, $(this).parents('tr').find("td").eq(1).html(),monitorType,condation,row);
			}
	    });
	} catch (e) {
		console.error(e);
		removeDataTableHeadClass();//移除表头对齐class
	}
    /**
     * 获取关联指标数据并绘制表格 
     */
	function fnFormatDetails(nTr, pdataId, monitorType, condation, row) {
		var code = $(nTr).children("td").find("input").val();
		var param=drgUI.setAjaxData(tabId);
			param.monitorType=monitorType;
		if (monitorType == "depGroup") {
			param.pardepgroupCode = code;
		}
		if (monitorType == "dep") {
			param.pardepCode = code;
		}
		if (monitorType == "ward") {
			param.parwardCode = code;
		}
		if (monitorType == "mdc") {
			param.parmdcCode = code;
		}
		if (monitorType == "adrg") {
			param.paradrgCode = code;
		}
		if (monitorType == "drgs") {
			param.pardrgCode = code;
		}
		if (monitorType == "clinic") {
			param.pargroupName = code;
		}
		
		if (monitorType == "resident") {
			param.resident = code;
		}
		if (monitorType == "physician") {
			param.physician = code;
		}
		if (monitorType == "resident") {
			param.resident = code;
		}
		var quotaCode = condation[0];
		var relQuota = condation[2];
		param.quotaCode=quotaCode + "_RELEATE";
		if (paramTabPage[tabId].compareType == "year") {
			compareName = "同期";
		} else if (paramTabPage[tabId].compareType == "month") {
			compareName = "上期";
		} else if (paramTabPage[tabId].compareType == "manage") {
			compareName = "绩效";
		} else if (paramTabPage[tabId].compareType == "std") {
			compareName = "标杆";
		}
		row.child("正在加载...").show();
		try {
			$.post(contextPath + "/DrgsIndexCal/indexCal.dhc",param).done(function(result) {
				if(result.success && result.data){
					var data = result.data;
					var str = '';
					str += ' <table "  ';
					str += ' width="100%" ';
					str += ' 	>  ';
					str += ' 	<thead>  ';
					str += ' 		<tr>  ';
					str += ' 			<td>指标名称</td>  ';
					str += ' 			<td>本期值</td>  ';
					str += ' 			<td>' + compareName + '值</td>  ';
					str += ' 			<td>增长率</td>  ';
					str += ' 		</tr>  ';

					str += ' 	</thead>  ';
					str += ' 	<tbody>  ';
					if(relQuota){
						for ( var o in relQuota) {
							var ly;
							var ty;
							if(relQuota.length==1){
								 ly = data[0] ? (data[0]["QuotaValuecc"] ? parseFloat(data[0]["QuotaValuecc"]): null): null;
								 ty = data[0] ? data[0]["QuotaValue"] : '';
							}else{
								 ly = data[0] ? (data[0][relQuota[o][0] + "cc"] ? parseFloat(data[0][relQuota[o][0] + "cc"]): null): null;
								 ty = data[0] ? data[0][relQuota[o][0]] : '';
							}
							str += "<tr>";
							str += "<td>" + relQuota[o][2] + "</td>"
							if (ty == 'undefined' || ty == null) {
								str += "<td> </td>"
								str += "<td> </td>"
							} else {
								str += "<td>" + formatNumber(ty)+ "</td>"
							}
							if (ly == 'undefined' || ly == null) {
								str += "<td> </td>"
								str += "<td> </td>"
							} else {
								str += "<td>" + formatNumber(ly)+ "</td>";
								if (relQuota[o][2].indexOf("%") > 0) {
									str += "<td>"+ gridcompareValuePercent(ty, ly) + "</td>"
								} else {
									str += "<td>"+ gridcompareValue(ty, ly)+ "</td>"
								}
							}
							str += "</tr>";
						}
					}
					str += ' 	</tbody>  ';
					str += ' </table>  ';
					row.child(str).show();
				}else{
					drgUI.warning("没有获取到相关数据！");
				}
		   });
		} catch (e) {
			row.child("出错了...").show();
		}
	}
	/**
	 * 
	 * ECharts图表数据实时更新
	 * 
	 */
function getPageDataYiBao(iDisplayStart,iDisplayLength,aiDisplay,aoData,npaging){
		
		var $this = npaging;
		var dataLen = aoData.length;
		//alert(iDisplayStart+"-----------"+iDisplayLength+"-----------"+aoData.length);
		var quotaCodeId = $this.parents('.dataChangeSel').parents('.tab-pane').attr("id");
		var monitorName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("monitorName");
		var quotaName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("quotaName");
		var quotaCode = $this.parents('.dataChangeSel').parents('.tab-pane').attr("quotaCode");
		var compareName = $this.parents('.dataChangeSel').parents('.tab-pane').attr("compareName");
		var compareType = paramTabPage[tabId].compareType;
		if(!compareName){
			compareName = "";
		}	
		var eChartsData = [];
		if(iDisplayLength < 0){
			iDisplayLength = aoData.length;
		}
		/*
		 * 获取datatables高度并赋值给echarts
		 */
		var echartsContainer = $("#"+tabId+" #"+quotaCodeId+" div div .echartscq");
		var datatabelContainer = $this.parents('.dataChangeSel');
		var datatablesHeight = datatabelContainer.height();
		if(datatablesHeight == 0){
			echartsContainer.height(250);
		}else if(datatablesHeight > 0 && dataLen < 4){
			echartsContainer.height(datatablesHeight+50);//此处不要减少高度，是解决系统不分页时，echarts里只有两个数据时的重叠问题
		}else{
			if(!pageing){
				echartsContainer.height(datatablesHeight+50)
			}
			else{
				echartsContainer.height(datatablesHeight)
			}
		}
		for (var i=iDisplayLength-1; i>=0; i--){
			var aDatanum = aiDisplay[iDisplayStart+i];
			if(typeof(aoData[aDatanum]) != "undefined"){
				var aData = aoData[aDatanum]._aData;
				if(compareName == ""){
					if(aData.ccode==null || aData.ccode=="null" ){
						eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue});
					}else{
						if(monitorName=="MDC"||monitorName=="ADRG"||monitorName=="DRG"){
							if(aData.ccode=="notcode"){
								eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue});
							}else{
								eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue});
							}
						}else{
							eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue});
						}
					}
				}else{
					if(aData.ccode==null || aData.ccode=="null" ){
						eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue,"ccodecc":aData.ccodecc,"QuotaValuecc":aData.QuotaValuecc,"ddesccc":aData.ddesccc});
					}else{
						if(monitorName=="MDC"||monitorName=="ADRG"||monitorName=="DRG"){
							if(aData.ccode=="notcode"){
								eChartsData.push({"ccode":"未入组","ddesc":"未入组","QuotaValue":aData.QuotaValue,"ccodecc":"未入组","QuotaValuecc":aData.QuotaValuecc,"ddesccc":"未入组"});
							}else{
								eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue,"ccodecc":aData.ccodecc,"QuotaValuecc":aData.QuotaValuecc,"ddesccc":aData.ddesccc});
							}
							
						}else{
							eChartsData.push({"ccode":aData.ccode,"ddesc":aData.ddesc,"QuotaValue":aData.QuotaValue,"ccodecc":aData.ccodecc,"QuotaValuecc":aData.QuotaValuecc,"ddesccc":aData.ddesccc});
						}
						
					}
					
				}
			}
		}
		var bars = [{"code": "QuotaValue", "desc": "本期"+$(".time_id").html(), "data":[]}, {"code": "QuotaValuecc", "desc":compareName+getTime(compareType), "data":[]}];
		var aaaData = eChartsData;
		drawCharts();
		function drawCharts(){
			var quotaCodeBarId = quotaCodeId.replace("-","bar-");
			if($('#'+quotaCodeBarId).size()>0){
				var chartParams={isHorizontal:true,isStack:false,legendPosition:'bottom',barMaxWidth:20};
				if(monitorName=="MDC" || monitorName=="ADRG" || monitorName=="DRG"){
					chartParams.showCode=true;
					barChart($("#"+quotaCodeBarId+" .echartscq"), bars, aaaData, quotaName+"统计", monitorName,chartParams);
				}else{
					barChart($("#"+quotaCodeBarId+" .echartscq"), bars, aaaData, quotaName+"统计", monitorName,chartParams);
				}
				$('#'+tabId+' a[href="#'+quotaCodeId+'"]').on('shown.bs.tab', function (e) {
					var chartParams={isHorizontal:true,isStack:false,legendPosition:'bottom',barMaxWidth:20};
					if(monitorName=="MDC" || monitorName=="ADRG" || monitorName=="DRG"){
						chartParams.showCode=true;
						barChart($("#"+quotaCodeBarId+" .echartscq"), bars, aaaData, quotaName+"统计",  monitorName,chartParams);
					}else{
						barChart($("#"+quotaCodeBarId+" .echartscq"), bars, aaaData, quotaName+"统计", monitorName,chartParams);
					}
				});
			}
			var quotaCodeLineId = quotaCodeId.replace("-","line-");
			if($('#'+quotaCodeLineId).size()>0){
				try{
					var ajaxs = [];
					var ajaxCount = 0;
					var lines = [];
					var linescode = [];
					var datas = [];
					var rowClick = function ($this, lineData) {
						if(ajaxs.length>0){
							return false;
						}
						var thisTr = $this.parent().parent();
						if($this.hasClass("trendNotSel"))
						{
							$this.removeClass("trendNotSel").addClass("trendSel");
						}
						else
						{
							$this.removeClass("trendSel").addClass("trendNotSel");
						}
						if(!$this.parents(".dataChangeSel").prev().find("ul>li>a[href*='line-']").parent().hasClass("active"))
			    		{//当趋势图页签没有显示时  显示趋势图页签
							$this.parents(".dataChangeSel").prev().find("ul>li>a[href*='line-']").click();
			    		}
						var bySelected = thisTr.parent().find("tr.even, tr.odd");
						getLineData(bySelected, lineData);
					};
					
					function getLineData(bySelected, lineData){
						for(var i=0; i<bySelected.length; i++){
							if(bySelected.eq(i).find(".trend-link").hasClass("trendSel")){
								ajaxCount++;
							}
						}
						if(ajaxCount<=0) {
							$("#"+quotaCodeLineId+" .echartscq").html('点击右侧表格趋势按钮<i class="fa fa-line-chart trend-link" />生成各'+monitorName+'趋势图');
							return;
						}
						$("#"+quotaCodeLineId+" .echartscq").html('<img src="images/pageloading.gif" />');
						var tablePageLength = bySelected.length;
						for(var i=0; i<bySelected.length; i++){
							if(bySelected.eq(i).find(".trend-link").hasClass("trendSel")){
								//上面的linedata 组装是倒着组装的  这里取也应该倒着取
								getDatas(lineData[tablePageLength-1-i].ccode, lineData[tablePageLength-1-i].ddesc.replace(/[\r\n]/g,""));
							}
						}
						var timerId = window.setInterval(function(){
							if(ajaxCount==0){
								window.clearInterval(timerId);
								var chartParams={legendPosition:'bottom'}
								if(monitorName=="MDC" || monitorName=="ADRG" || monitorName=="DRGs"){
									chartParams.showCode=true;
									lineChartBasic($("#"+quotaCodeLineId+" .echartscq"), linescode, datas, quotaName+"趋势图",'',chartParams);
								}else{
									lineChartBasic($("#"+quotaCodeLineId+" .echartscq"), lines, datas, quotaName+"趋势图",'',chartParams);
								}
								ajaxs = [];
								lines = [];
								linescode = [];
								datas = [];
							}
						}, 1000);

					}
					
					function getDatas(ccode, ddesc){
						var pType = paramTabPage[tabId].pType ? paramTabPage[tabId].pType: "";
						var depGroupCode = paramTabPage[tabId].depGroupCode ? paramTabPage[tabId].depGroupCode: "";
						var depCode = paramTabPage[tabId].depCode ? paramTabPage[tabId].depCode: "";
						var wardCode=paramTabPage[tabId].wardCode?paramTabPage[tabId].wardCode:"";
						var groupName = paramTabPage[tabId].groupName ? paramTabPage[tabId].groupName: "";
						var protomedicus=paramTabPage[tabId].protomedicus?paramTabPage[tabId].protomedicus:"";//主任医师
						var physician=paramTabPage[tabId].physician?paramTabPage[tabId].physician:"";//主治医师
						var resident=paramTabPage[tabId].resident?paramTabPage[tabId].resident:"";//住院医师
						var protomedicus = paramTabPage[tabId].protomedicus ? paramTabPage[tabId].protomedicus: "";
						var mdcCode = paramTabPage[tabId].mdcCode ? paramTabPage[tabId].mdcCode: "";
						var adrgCode = paramTabPage[tabId].adrgCode ? paramTabPage[tabId].adrgCode: "";
						var drgCode = paramTabPage[tabId].drgCode ? paramTabPage[tabId].drgCode: "";
						
						var type =monitorType;
						switch(type)
						 {
						 case "depGroup":
							 depGroupCode=ccode;
							 break;
						 case "dep":
							 depCode=ccode;
							 break;
						 case "ward":
							 wardCode=ccode;
							 break;
						 case "clinic":
							 groupName=ccode;
							 break;
						 case "protomedicus"://主任医师
							 protomedicus=ccode;
							 break;
						 case "physician"://主治医师
							 physician=ccode;
							 break;
						 case "resident"://住院医师
							 resident=ccode;
							 break;
						 case "mdc":
							 mdcCode=ccode;
							 break;
						 case "adrg":
							 adrgCode=ccode;
							 break;
						 case "drgs":
							 drgCode=ccode;
							 break;
						 }
						var ajax = $.post(contextPath+ "/ywcHome/getCMIDRGCount.dhc",
						{
							'mrLot' : paramTabPage[tabId].mrLot,
							'mrType' : paramTabPage[tabId].mrType,
							'dateFrom' : paramTabPage[tabId].dateFrom,
							'dateTo' : paramTabPage[tabId].dateTo,
							'pType' :pType,
							'monitorType' : type,
							'quotaCode' : quotaCode,
							'pardepCode' : depCode,
							'pardepgroupCode' : depGroupCode,
							'parwardCode': wardCode,
			        		'physician' :physician,
			        		'resident' :resident,
							'pargroupName' : groupName,
							'protomedicus' : protomedicus,
							'parmdcCode' : mdcCode,
							'paradrgCode' : adrgCode,
							'pardrgCode' : drgCode
						})
						.done(function(data) {
							var data = data.data;
							if(data.length>0){
								datas.push(data);
								var line = {"code":"QuotaValue", "desc":ddesc, data: []}
								if(ccode=="null"){
									ccode="未入组";
								}
								var linecode = {"code":"QuotaValue", "desc":ddesc, data: [],"ccode":ccode}//添加ccode参数使折线图上方的说明变为code
								lines.push(line);
								linescode.push(linecode);
							}
							ajaxCount--;
						});
						ajaxs.push(ajax);
					}
						datatable.find('tbody > tr').each(function () {
							var lineTr = $(this);
							if(typeof(lineTr.attr("class")) != "undefined"){
								lineTr.find('td:last .trend-link').unbind( 'click' );
								lineTr.find('td:last .trend-link').bind( 'click', function () {rowClick($(this), aaaData)});
							}else{
								lineTr.remove();
							}
						});
						getLineData(datatable.find('tbody > tr'), aaaData);
				}catch(e){
					ajaxs = [];
					lines = [];
					linescode = [];
					datas = [];
					ajaxCount=0;
				}
			}
		}
	}
};

function loadSubPagePieChart(start,end,data,tableid,param){
	var id = param.id;
	var field = param.field;
	var title = param.title;
	var ignore = param.ignore;
	var nameCode = param.nameCode;
	var datalength = data.length;
	var length = id.length;
	var chartIdParent  = tableid.parents(".dataChangeSel").prev();
	if(ignore && datalength==end)//是否忽略最后一条
		end = end-1;
	for(var i=0; i<length;i++)
	{
		var chartdata = [];
		for (var j=start; j<end; j++){
			var aData = data[j]._aData;
			chartdata.push({name:aData[nameCode],value:aData[field[i]]});
		}
		chartIdParent.find("#"+id[i])
		pieCharts(chartIdParent.find("#"+id[i]), chartdata, title[i], '');
	}
}




/**
 * datatable函数扩展 医政病例分析
 * columns 自定义列
 * data 数据源
 * paging 是否分页(0、1)
 * searching 是否启用过滤(0、1)
 * bSort 是否启用排序(0、1)
 * sortCols 排序列(0、1、2、3、4...)
 * aTargets 启用某列不排序
 * callBackParam {id:['id1','id2','id3'],nameCode:'code',field:['field1','field2','field3'],title:['title1','title2'],ignore:true,mergeCol:[1,2,3]}
 */
jQuery.fn.caseAnalysisDataTable=function(columns, data, paging, searching, bSort, sortCols,aTargets,callBackParam){
	addDataTableHeadClass();//添加表头对齐class
	data=data!=undefined?data:[];//传入的数据源为空时，处理为[]
	var datatable = $(this);
	var _paging = paging=="1"?true:false;
	var _searching = searching=="1"?true:false;
	var _bSort = bSort=="0"?false:true;
	var _sortCols = sortCols?sortCols:0;
	var _iDisplayLength = 10;
	
	var buttonsCustom = jQuery.extend(true, [],buttonsCommon);//此处复制时，用[],不用{}
	if(exportEnable) {
    	buttonsCustom[0].buttons[0].filename = '*';
    	buttonsCustom[0].buttons[1].filename = '*';
    	if(datatable.parents().hasClass('dataChangeSel')){
			var $currdt = datatable.parents(".dataChangeSel");
			var titleText=$currdt.find(".contaotalsccq").text();
			if(titleText!=''){
				buttonsCustom[0].buttons[0].filename=titleText;
				buttonsCustom[0].buttons[1].filename=titleText;
			}
		}
    }
	var option = {
		"destroy": true,
		"paging": _paging, //翻页功能
		"lengthChange": true, //改变每页显示数据数量
		"searching": _searching, //过滤功能
		"info": false, //页脚信息
	    "data": data,
	    "stateSave": false, 
	    "buttons":buttonsCustom,
	    "ordering": _bSort,
	    "pageLength": _iDisplayLength,
	    "jQueryUI": false,
	    "columnDefs": [
	                     {
	                    	 defaultContent: '',
	                    	 targets: [ '_all' ]
	                     },
	                     { 
	                    	 "orderable": false, 
	                    	 "targets": [ aTargets ] 
	                     }
	                     ],
	    "order": [
	                  [ _sortCols, "asc" ]
	             ],
        "pagingType": "full_numbers",
	    "lengthMenu": [[10,20,30,50,-1], [10,20,30,50,"All"]],
	    "columns": columns,
	    "language":languageCommon,
	    "initComplete": function(settings, json) {		
	    	removeDataTableHeadClass();  //移除表头对齐class
	    },//绘制完后
	    "drawCallback": function( oSettings ) {
	    	 //table加载完成后回调事件
	    	  /*
	    	   * 加载图表，更新数据,修改表头样式
	    	   */
	          if(datatable.parents().hasClass('dataChangeSel')){
	        	  //自动加载当前分页的图
	        	  loadSubPagePieChart(oSettings._iDisplayStart,oSettings._iDisplayEnd,oSettings.aiDisplay,oSettings.aoData,datatable,callBackParam);
		      }else if(typeof(callBackParam)!="undefined"&&typeof(callBackParam.mergeCol)!="undefined"){
	        	  var mergeCol= callBackParam.mergeCol;
	        	  for(var i=0;i<mergeCol.length;i++){
		        	  this.rowspan(i);
		          }
	          }
	          
	    	} 
		}
	var table;
	try {
		table = $(this).DataTable(option);
	} catch (e) {
		console.error(e);
		removeDataTableHeadClass();//移除表头对齐class
	}
};

function loadSubPagePieChart(start,end,aiDisplay,data,tableid,param){
	var id = param.id;
	var field = param.field;
	var title = param.title;
	var ignore = param.ignore;
	var nameCode = param.nameCode;
	var datalength = data.length;
	var length = id.length;
	var chartIdParent  = tableid.parents(".dataChangeSel").prev();
	if(ignore && datalength==end)//是否忽略最后一条
		end = end-1;
	for(var i=0; i<length;i++)
	{
		var chartdata = [];
		for (var j=start; j<end; j++){
			var aDatanum = aiDisplay[j];
			var aData = data[aDatanum]._aData;
			chartdata.push({name:aData[nameCode],value:aData[field[i]]});
		}
		chartIdParent.find("#"+id[i])
		pieCharts(chartIdParent.find("#"+id[i]), chartdata, title[i], '');
	}
}

/**
 * dataTable合并单元格方法
 */
jQuery.fn.rowspan = function(colIdx) {
	return this.each(function(){ 
		$('tr', this).each(function(row) { 
			$('td:eq('+colIdx+')', this).each(function(col) { 
				$(this).removeAttr("rowspan");
				$(this).removeAttr("style");
			});
		});
		var that; 
		$('tr', this).each(function(row) { 
			$('td:eq('+colIdx+')', this).each(function(col) { 
				if (that!=null && $(this).html() == $(that).html()) { 
					var rowspan = $(that).attr("rowSpan"); 
					if (rowspan == undefined) { 
						$(that).attr("rowSpan",1); 
						rowspan = $(that).attr("rowSpan"); 
					} 
					rowspan = Number(rowspan)+1; 
					$(that).attr("rowSpan",rowspan); 
					$(this).hide(); 
				} else { 
					that = this; 
				} 
			}); 
		}); 
	}); 
}

/**
 * datatable单元格内容过多的处理方法
 */
jQuery.fn.limit=function(){
    var self = $(this);
    var num = $(this).attr("limit");
    if(self.find("a").size()>0) self = self.find("a:eq(0)");
    self.each(function(){
          var objString = $(this).text();
          var objLength = $(this).text().length;
          if(objLength > num){
                 $(this).attr("title",objString);
                 objString = $(this).text(objString.substring(0,num) + "...");
         }
      })
}



/**
 * 
 * @ Discription:添加tab页的表头对其class
 * @Autor ：liuhongjun
 * @param table
 * @returns
 * any
 * drgsDataTables.js
 * 2017年7月17日上午11:18:02
 */
function addDataTableHeadClass() {
	$(".tab-pane").addClass('dataTableHead');
}
/**
 * 
 * @ Discription:移除tab的表头对齐class样式
 * @Autor ：liuhongjun
 * @param table
 * @returns
 * any
 * drgsDataTables.js
 * 2017年7月17日上午11:17:27
 */
function removeDataTableHeadClass() {
	$(".tab-pane").removeClass('dataTableHead');
}
/**
 * 表格列排序问题
 */
jQuery.fn.dataTableExt.oSort['perf-desc']  = function(s1,s2) {
    if(s1==='全院'){
        return -1;
    }
    if(s2==='全院'){
        return 1;
    }
    return s2.localeCompare(s1);
}
jQuery.fn.dataTableExt.oSort['perf-asc']  = function(s1,s2) {
    if(s1==='全院'){
        return -1;
    }
    if(s2==='全院'){
        return 1;
    }
    return s1.localeCompare(s2);
}


/**
 * @Description: 记录表格导出日志
 * @Author: chenhanlin
 * @date: 2019/2/16
 */
function exportTableLog() {
    $(".buttons-collection").click(function () {
        $(".buttons-html5").click(function () {
            // 记录导出数据日志
            var tabTitle = paramsDataTables.tableTitle ;
            var desc = "" ;
            if(tabTitle) {
                desc = tabTitle+"数据" ;
            } else {
                desc = $('title').text()+"数据" ;
            }
            $.ajax({
                type: "POST",
                url: contextPath + "/log/exportTableLog.dhc",
                data: {"desc":desc},
                dataType: "json",
                success: function (data) {}
            });
        })
    });
}